<?php
/**
 * Description
 * 
 * PHP version 7
 * 
 * @category Custom
 * @package  Custom
 * @author   ryu <mo5467@126.com>
 * @date     2020-04-25 13:47:18
 * @lastTime 2020-05-01 23:13:37
 * @license  https://opensource.org/licenses/MIT MIT License
 * @link     none
 */

namespace Test\Unit;

use Psr\Http\Message\UriInterface;
use Psr\Http\Message\RequestInterface;
use Design\Behavioral\ChainOfResponsibilities\FastResponse;
use Design\Behavioral\ChainOfResponsibilities\SlowResponse;

class ChainOfResponsibilities extends \Test\BaseTest
{

    private $handler = null;


    public function setUp(): void
    {
        $this->handler = new FastResponse(
            ['/foo/bar?index=1' => 'Hello Fast'],
            new SlowResponse()
        );

    }//end setUp()


    public function testCanRequestInFastResponse()
    {
        $uri = $this->createMock(UriInterface::class);
        $uri->method('getPath')->willReturn('/foo/bar');
        $uri->method('getQuery')->willReturn('index=1');

        $request = $this->createMock(RequestInterface::class);
        $request->method('getMethod')->willReturn('GET');
        $request->method('getUri')->willReturn($uri);

        $this->assertSame('Hello Fast', $this->handler->handle($request));

    }//end testCanRequestInFastResponse()


    public function testCanRequestInSlowResponse()
    {
        $uri = $this->createMock(UriInterface::class);
        $uri->method('getPath')->willReturn('/foo/null');
        $uri->method('getQuery')->willReturn('');

        $request = $this->createMock(RequestInterface::class);
        $request->method('getMethod')->willReturn('GEt');
        $request->method('getUri')->willReturn($uri);

        $this->assertSame('Hello World', $this->handler->handle($request));

    }//end testCanRequestInSlowResponse()


}//end class
